<?php
/**
 * Created by litong on Date: 2019/2/23 0023 下午 12:36
 * 测试mysql连接,mysql连接,面向对象
 * @see php16.mysql.docx
 */
$host="localhost";
$username="root";
$password="";
//创建连接
$connection = new mysqli($host, $username, $password);
//检测连接
if($connection->connect_error){
  die("连接失败"+$connection->connect_errno."\n");
}
echo "连接成功"."\n";
$connection->close();//关闭连接

/**
 * mysql连接,面向过程
 */
$connection = mysqli_connect($host, $username, $password);
if(!$connection){
  die("连接失败:".mysqli_connect_error()."\n");
}
echo "连接成功"."\n";
mysqli_close($connection); //关闭连接
/**
 * 使用pdo连接mysql
 */
try{
  $connection = new PDO("mysql:host=$host", $username, $password);
  echo "连接成功";
}catch(PDOException $e){
  echo $e->getMessage();
}
$connection=null;


